package com.wf.classRoomTest.excutors;

import com.sun.security.auth.SolarisPrincipal;

import java.util.concurrent.*;

/**
 * @author mpk
 * @since 2024/6/13 14:28:06
 */
public class ExecutorsTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ExecutorService single = Executors.newSingleThreadExecutor();

        ExecutorService fixed = Executors.newFixedThreadPool(10);

        ExecutorService cached = Executors.newCachedThreadPool();

        ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(10);


        single.execute(() -> System.out.println(Thread.currentThread().getName()+"single"));
        single.execute(() -> System.out.println(Thread.currentThread().getName()+"single"));
        fixed.execute(() -> System.out.println("fixed"));
        Future<String> fixed1 = fixed.submit(() -> {
            System.out.println("fixed");
            return "A";
        });

        Object o = fixed1.get();
        System.out.println(o);
        cached.execute(() -> System.out.println("cached"));
        scheduled.execute(() -> System.out.println("scheduled"));
        single.shutdown();
        fixed.shutdown();


        scheduled.shutdown();

        while (true)
        {
            cached.submit(() -> {

                String s="A";

                System.out.println(Thread.currentThread().getName() + "-->" +"cache");
                        try {
                            s.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
            );
        }
       // cached.shutdown();

    }


}
